package com.luo.service;

import com.luo.dao.impl.ClassDaoImpl;
import com.luo.model.Goods;
import com.luo.model.OneClass;
import com.luo.model.OneTwoClass;
import com.luo.model.TwoClass;
import com.luo.util.RandomUtil;

import java.util.List;
import java.util.Random;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/1/9 16:16
 */
public class ClassService {

	ClassDaoImpl classDao = new ClassDaoImpl();

	public List<OneClass> queryAllOneClass() {
		List<OneClass> oneClasses = classDao.queryAllOneClass();
		return oneClasses;
	}

	public List<TwoClass> queryAllTwoClass() {
		List<TwoClass> twoClasses = classDao.queryAllTwoClass();
		return twoClasses;
	}

	public List<OneClass> queryLimitOneClass() {
		List<OneClass> oneClasses = classDao.queryLimitOneClass();
		return oneClasses;
	}

	public List<TwoClass> queryTwoClassByOneId(final OneClass oneClass) {
		List<TwoClass> twoClasses = classDao.queryTwoClassByOneId(oneClass);
		return twoClasses;
	}

	public TwoClass queryTwoClassByTwoId(String id) {
		TwoClass twoClass = classDao.queryTwoClassByTwoId(id);
		return twoClass;
	}

	public List<Goods> queryGoodsByOneId(OneClass oneClass) {
		List<Goods> goods = classDao.queryGoodsByOneId(oneClass);
		for (Goods good : goods) {
			Double disCount = Double.valueOf(good.getDiscount()) / 10;
			Double price = Double.valueOf(good.getPrice());
			if (disCount > 0.0) {
				good.setOldPrice(String.format("%.2f", price * disCount));
			} else {
				good.setOldPrice(String.format("%.2f", price));
			}
		}
		return goods;
	}

	public OneClass queryOneClassByOneId(String id) {
		OneClass oneClass = classDao.queryOneClassByOneId(id);
		return oneClass;
	}

	public List<TwoClass> queryTwoClassByOneName(final String name) {
		List<TwoClass> twoClasses = classDao.queryTwoClassByOneName(name);
		return twoClasses;
	}

	public String queryOneClassByName(String name) {
		String s = classDao.queryOneClassByName(name);
		return s;
	}

	public String queryTwoClassByName(String name) {
		String s = classDao.queryTwoClassByName(name);
		return s;
	}

	public int AddOneClass(final OneClass oneClass) {
		StringBuffer stringBuffer = new StringBuffer("100");
		String random = RandomUtil.getRandom(4);
		oneClass.setId(Integer.parseInt(random));
		int i = classDao.AddOneClass(oneClass);
		return i;
	}

	public int AddTwoClass(final TwoClass twoClass) {
		StringBuffer stringBuffer = new StringBuffer("100");
		String random = RandomUtil.getRandom(4);
		twoClass.setId(Integer.parseInt(random));
		int i = classDao.AddTwoClass(twoClass);
		return i;
	}

	public List<OneTwoClass> queryOneTwoClassByOneId(final OneClass oneClass) {
		List<OneTwoClass> oneTwoClasses = classDao.queryOneTwoClassByOneId(oneClass);
		return oneTwoClasses;
	}

	public int deleteOneClass(List<String> list) {
		int i = classDao.deleteOneClass(list);
		return i;
	}

	public int deleteTwoClass(List<String> list) {
		int i = classDao.deleteTwoClass(list);
		return i;
	}

	public int updateOneClass(final OneClass oneClass) {
		int i = classDao.updateOneClass(oneClass);
		return i;
	}

	public int updateTwoClass(final TwoClass twoClass) {
		int i = classDao.updateTwoClass(twoClass);
		return i;
	}
}
